import Vue from 'vue'
import Router from 'vue-router'
import storage from '../lib/storage'
import {
  MessageBox
} from 'element-ui'

const Main = resolve => require(['../components/Main'], resolve)
const Index = resolve => require(['../components/view/Index'], resolve)

const Course = resolve => require(['../components/teachResearch/course/Course'], resolve)
const CourseDetail = resolve => require(['../components/teachResearch/course/CourseDetail'], resolve)
const ViewLecture = resolve => require(['../components/teachResearch/course/ViewLecture'], resolve)
const EditLecture = resolve => require(['../components/teachResearch/course/EditLecture'], resolve)
const Sheet = resolve => require(['../components/teachResearch/course/Sheet'], resolve)
const AddSheet = resolve => require(['../components/teachResearch/course/AddSheet'], resolve)
const Lecture = resolve => require(['../components/teachResearch/lecture/Lecture'], resolve)
const LectureDetail = resolve => require(['../components/teachResearch/lecture/LectureDetail'], resolve)
const Data = resolve => require(['../components/teachResearch/data/Data'], resolve)
const DataDetail = resolve => require(['../components/teachResearch/data/DataDetail'], resolve)
//  系统管理
const System = resolve => require(['../components/view/System'], resolve)
const BasisSetContainer = resolve => require(['../components/system/BasisSetContainer'], resolve)
const SchoolSetting = resolve => require(['../components/system/basis/SchoolSetting'], resolve)
const TermSetting = resolve => require(['../components/system/basis/TermSetting'], resolve)
const ClassSetting = resolve => require(['../components/system/basis/ClassSetting'], resolve)
const OrganizationContainer = resolve => require(['../components/system/OrganizationContainer'], resolve)
const PersonalOperateContainer = resolve => require(['../components/system/PersonalOperateContainer'], resolve)
const PersonalOperateList = resolve => require(['../components/system/organization/PersonalOperateList'], resolve)
const PersonalOperateDetail = resolve => require(['../components/system/organization/PersonalOperateDetail'], resolve)
const OrganizationList = resolve => require(['../components/system/organization/OrganizationList'], resolve)
const OrganizationDetail = resolve => require(['../components/system/organization/OrganizationDetail'], resolve)
const UserListContainer = resolve => require(['../components/system/UserListContainer'], resolve)
const UserList = resolve => require(['../components/system/user/UserList'], resolve)
const UserAdd = resolve => require(['../components/system/user/UserAdd'], resolve)
const UserDetail = resolve => require(['../components/system/user/UserDetail'], resolve)
const CharacterList = resolve => require(['../components/system/character/CharacterList'], resolve)
const CharacterAdd = resolve => require(['../components/system/character/CharacterAdd'], resolve)
const ParadigmSetting = resolve => require(['../components/system/character/ParadigmSetting'], resolve)
const PermissionSetting = resolve => require(['../components/system/character/PermissionSetting'], resolve)
const CharacterListContainer = resolve => require(['../components/system/CharacterListContainer'], resolve)
// 报表管理
const CourseTableContainer = resolve => require(['../components/system/CourseTableContainer'], resolve)
const CourseTable = resolve => require(['../components/system/table/CourseTable'], resolve)
//  班级管理
const ClassListContainer = resolve => require(['../components/system/ClassListContainer'], resolve)
const ClassList = resolve => require(['../components/system/class/ClassList'], resolve)
const AddClass = resolve => require(['../components/system/class/AddClass'], resolve)
const ClassDetails = resolve => require(['../components/system/class/ClassDetails'], resolve)
const ClassStudentList = resolve => require(['../components/system/class/ClassStudentList'], resolve)
const Score = resolve => require(['../components/system/class/Score'], resolve)
const AddClassStudent = resolve => require(['../components/system/class/AddClassStudent'], resolve)
//  学员管理
const StudentsContainer = resolve => require(['../components/system/StudentsContainer'], resolve)
const StudentList = resolve => require(['../components/system/student/StudentList'], resolve)
const AddStudent = resolve => require(['../components/system/student/AddStudent'], resolve)
// 组卷
const Exam = resolve => require(['../components/view/Exam'], resolve)
const TestPaper = resolve => require(['../components/exam/TestPaper'], resolve)
const Active = resolve => require(['../components/exam/ActiveList'], resolve)
const ActiveDetail = resolve => require(['../components/exam/ActiveDetail'], resolve)
const TestPaperDetail = resolve => require(['../components/exam/TestPaperDetail'], resolve)
const AddModule = resolve => require(['../components/exam/AddModule'], resolve)
const SetUse = resolve => require(['../components/exam/SetUse'], resolve)
// 文案模版
const Module = resolve => require(['../components/exam/modules/Module'], resolve)
const ModuleDetail = resolve => require(['../components/exam/modules/ModuleDetail'], resolve)
//教学
const TeachResearch = resolve => require(['../components/view/TeachResearch'], resolve)
const AttendClass = resolve => require(['../components/view/AttendClass'], resolve)
// 备课
const PrepareLessons = resolve => require(['../components/view/PrepareLessons'], resolve)
const CourseWare = resolve => require(['../components/prepareLessons/CourseWare'], resolve)
// 上课
const AttendContent = resolve => require(['../components/attend-class/AttendContent'], resolve)
// 登陆
const Login = resolve => require(['../components/login/Login'], resolve)
//个人信息
const Personal = resolve => require(['../components/personal/Personal'], resolve)
const UserInfo = resolve => require(['../components/personal/UserInfo'], resolve)
const ChangePassword = resolve => require(['../components/personal/ChangePassword'], resolve)
const Pdf = resolve => require(['../components/view/Pdf'], resolve)

// 学员报告
const ReportList = resolve => require(['../components/report/ReportList'], resolve)
const ReportDetail = resolve => require(['../components/report/ReportDetail'], resolve)
const FeedbackList = resolve => require(['../components/feedback/FeedbackList'], resolve)
Vue.use(Router)

const router = new Router({
  mode: process.env.NODE_ENV === 'production' ? 'hash' : 'hash',
  routes: [
    {
      path: '/main',
      component: Main,
      children: [
        {
          path: "exam",
          component: Exam,
          children: [{
            path: 'test-paper',
            component: TestPaper
          }, {
            path: 'test-paper/:id',
            component: TestPaperDetail
          }, {
            path: 'add-module',
            component: AddModule
          }, {
            path: 'set-use',
            component: SetUse
          }, {
            path: 'active',
            component: Active
          }, {
            path: 'active/:id',
            component: ActiveDetail
          }, {
            path: 'module',
            component: Module
          }, {
            path: 'module/:id',
            component: ModuleDetail
          }]
        },
        {
          path: "teach-research",
          component: TeachResearch,
          children: [{
            path: 'course',
            component: Course,
            meta: { keepAlive: true }
          }, {
            path: 'course/:id',
            component: CourseDetail
          }, {
            path: 'course/edit-lecture/:id',
            component: EditLecture
          }, {
            path: 'course/view-lecture/:sourceType/:courseId/:chapterId',
            component: ViewLecture,
          },
          {
            path: 'course/sheet/:id',
            component: Sheet
          },
          {
            path: 'course/add-sheet/:id',
            component: AddSheet
          },
          {
            path: 'lecture',
            component: Lecture,
            meta: { keepAlive: true }
          }, {
            path: 'lecture/:id',
            component: LectureDetail
          }, {
            path: 'data',
            component: Data,
            meta: { keepAlive: true }
          }, {
            path: 'data/:id',
            component: DataDetail
          }]
        },
        {
          path: "attend-class",
          component: AttendClass,
          meta: { keepAlive: true }
        },
        {
          path: "attend-content/:lessonId/:id",
          component: AttendContent,
        },
        {
          path: "prepare-lessons",
          component: PrepareLessons,
          meta: { keepAlive: true }
        },
        {
          path: "prepare-lessons/:id/:sourceType/:optType",
          component: CourseWare
        }, {
          path: 'system',
          component: System,
          children: [{
            path: 'basisSetting',
            component: BasisSetContainer,
            children: [{
              path: 'schoolSetting',
              component: SchoolSetting
            }, {
              path: 'termSetting',
              component: TermSetting
            }, {
              path: 'classSetting',
              component: ClassSetting
            }
            ]
          }, {
            path: 'table',
            component: CourseTableContainer,
            children: [{
              path: 'courseTable',
              component: CourseTable
            }]
          }, {
            path: 'userList',
            component: UserListContainer,
            children: [{
              path: 'list',
              component: UserList
            }, {
              path: 'userAdd',
              component: UserAdd
            }, {
              path: 'userDetail',
              component: UserDetail
            }
            ]
          }, {
            path: 'characterList',
            component: CharacterListContainer,
            children: [{
              path: 'list',
              component: CharacterList
            }, {
              path: 'paradigmSetting',
              component: ParadigmSetting
            }, {
              path: 'permissionSetting',
              component: PermissionSetting
            }, {
              path: 'add',
              component: CharacterAdd
            }]
          }, {
            path: 'organization',
            component: OrganizationContainer,
            children: [{
              path: 'list',
              component: OrganizationList
            }, {
              path: 'list/:type',
              component: OrganizationDetail
            }]
          }, {
            path: 'personal',
            component: PersonalOperateContainer,
            children: [{
              path: 'list',
              component: PersonalOperateList
            }, {
              path: 'list/:type',
              component: PersonalOperateDetail
            }]
          }, {
            path: 'class',
            component: ClassListContainer,
            children: [
              {
                path: 'list',
                component: ClassList
              },
              {
                path: "details",
                component: ClassDetails,
              },
              {
                path: "student-list",
                component: ClassStudentList,
              },
              {
                path: 'report',
                component: ReportList
              },
              {
                path: 'feedback',
                component: FeedbackList
              }, {
                path: "score",
                component: Score,
              }, {
                path: "add-class-student",
                component: AddClassStudent,
              },
              {
                path: ":id",
                component: AddClass,
              },
            ]
          }, {
            path: 'student',
            component: StudentsContainer,
            children: [
              {
                path: 'list',
                component: StudentList
              },
              {
                path: ":id",
                component: AddStudent,
              }
            ]
          }
          ]
        }
      ]
    },
    {
      path: '/',
      component: Index
    }, {
      path: '/index',
      component: Index
    }, {
      path: '/login',
      component: Login
    },
    {
      path: '/personal',
      component: Personal,
      children: [
        {
          path: 'user-info',
          component: UserInfo
        },
        {
          path: 'change-password',
          component: ChangePassword
        }
      ]
    },
    {
      path: '/pdf',
      component: Pdf
    },
    {
      path: "/report-detail",
      component: ReportDetail
    }
  ]
})
router.beforeEach((to, from, next) => {
  let token = storage.getAccessToken()
  if (!token && to.path.indexOf('/login') === -1) {
    next({ path: '/login', query: { backUrl: from.fullPath } })
  } else {
    next()
  }
})
export default router